package cn.iocoder.yudao.module.famous.doctor.controller.admin.forumRecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.forumRecord.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.forumRecord.FamForumRecordDO;
import cn.iocoder.yudao.module.famous.doctor.convert.forumRecord.FamForumRecordConvert;
import cn.iocoder.yudao.module.famous.doctor.service.forumRecord.FamForumRecordService;

@Tag(name = "管理后台 - 点赞/收藏--记录表")
@RestController
@RequestMapping("/famous.doctor/fam-forum-record")
@Validated
public class FamForumRecordController {

    @Resource
    private FamForumRecordService famForumRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建点赞/收藏--记录表")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-forum-record:create')")
    public CommonResult<Long> createFamForumRecord(@Valid @RequestBody FamForumRecordCreateReqVO createReqVO) {
        return success(famForumRecordService.createFamForumRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新点赞/收藏--记录表")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-forum-record:update')")
    public CommonResult<Boolean> updateFamForumRecord(@Valid @RequestBody FamForumRecordUpdateReqVO updateReqVO) {
        famForumRecordService.updateFamForumRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除点赞/收藏--记录表")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-forum-record:delete')")
    public CommonResult<Boolean> deleteFamForumRecord(@RequestParam("id") Long id) {
        famForumRecordService.deleteFamForumRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得点赞/收藏--记录表")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-forum-record:query')")
    public CommonResult<FamForumRecordRespVO> getFamForumRecord(@RequestParam("id") Long id) {
        FamForumRecordDO famForumRecord = famForumRecordService.getFamForumRecord(id);
        return success(FamForumRecordConvert.INSTANCE.convert(famForumRecord));
    }

    @GetMapping("/list")
    @Operation(summary = "获得点赞/收藏--记录表列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-forum-record:query')")
    public CommonResult<List<FamForumRecordRespVO>> getFamForumRecordList(@RequestParam("ids") Collection<Long> ids) {
        List<FamForumRecordDO> list = famForumRecordService.getFamForumRecordList(ids);
        return success(FamForumRecordConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得点赞/收藏--记录表分页")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-forum-record:query')")
    public CommonResult<PageResult<FamForumRecordRespVO>> getFamForumRecordPage(@Valid FamForumRecordPageReqVO pageVO) {
        PageResult<FamForumRecordDO> pageResult = famForumRecordService.getFamForumRecordPage(pageVO);
        return success(FamForumRecordConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出点赞/收藏--记录表 Excel")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-forum-record:export')")
    @OperateLog(type = EXPORT)
    public void exportFamForumRecordExcel(@Valid FamForumRecordExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<FamForumRecordDO> list = famForumRecordService.getFamForumRecordList(exportReqVO);
        // 导出 Excel
        List<FamForumRecordExcelVO> datas = FamForumRecordConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "点赞/收藏--记录表.xls", "数据", FamForumRecordExcelVO.class, datas);
    }

}
